﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using gfPage;
using gfLibrary;
using DBUtility;
using Model;
using BLL;
using Config;

namespace LabourVerify
{
    public partial class LabourVerifySearch : System.Web.UI.Page
    {
                
        protected void Page_Load(object sender, EventArgs e)
        {
             gfAjaxJs.SetNoCache();

             if (Page.IsPostBack == false)
             {
                btnSearch_Click(null,null);
             }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strKeywords = txtKeywords.Text;
            string strSQL = "SELECT ID,JCXH,JYXM,YJXM,JCLSH,AJLSH,HPHM,HPZL,JYLB,ISNULL(YCY,'') AS YCY,VIN,FJXM, JCZT_STATUS,GXRQ FROM VEHICLE_DISPATCH WHERE LEFT(JCLSH,1) != 'P'  ";
            
            if (strKeywords.Length > 0)
            {
                strSQL += " AND (";
                strSQL += " JCLSH like '%" + strKeywords + "%'";
                strSQL += " or JCXH like '%" + strKeywords + "%'";
                strSQL += " or JYXM like '%" + strKeywords + "%'";
                strSQL += " or JCLSH like '%" + strKeywords + "%'";
                strSQL += " or AJLSH like '%" + strKeywords + "%'";
                strSQL += " or HPHM like '%" + strKeywords + "%'";
                strSQL += " or HPZL like '%" + strKeywords + "%'";
                strSQL += " or JYLB like '%" + strKeywords + "%'";
                strSQL += " or YCY like '%" + strKeywords + "%'";
                strSQL += " or GXRQ like '%" + strKeywords + "%'";
                strSQL += " or VIN like '%" + strKeywords + "%'";
                strSQL +=  ")";
            }

            strSQL += "  ORDER BY ID DESC";
            DataTable m_dtTable = new DataTable();
            GreatPager1.BindDataTablePage(ref m_dtTable, AppConfig.g_strConnectionStringSqlClient, strSQL, 20);

            rptList.DataSource = m_dtTable;
          
            rptList.DataBind();
            m_dtTable.Dispose();
        }

        protected void GreatPager1_PageIndexChanging(object sender, gfPage.PagerEventArgs e)
        {
            GreatPager1.PageIndex = e.NewPageIndex;
            btnSearch_Click(sender, null);
         }

        protected void btnSearchAll_Click(object sender, EventArgs e)
        {
            txtKeywords.Text = "";
            btnSearch_Click(sender, e);
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];

            if((strUniqueKey == null)||(strUniqueKey.Length == 0))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            Response.Redirect("LabourVerifySearch_Detail.aspx?UniqueKey=" + strUniqueKey);
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];
            Response.Redirect("equip_type_Insert_Update.aspx?m=u&UniqueKey=" + strUniqueKey);
        }
    }
}
